package com.music.mysongs.db

import android.content.Context
import android.database.sqlite.SQLiteDatabase
import android.database.sqlite.SQLiteOpenHelper
import com.music.mysongs.utils.myLog

class MusicDataBase(val context: Context, name: String, version: Int) :
    SQLiteOpenHelper(context, name, null, version) {
    //AUTOINCREMENT自增主键
    private val createTableMusic = "CREATE TABLE \"musicDB\" (" +
            "\"id\" integer NOT NULL PRIMARY KEY AUTOINCREMENT," +
            "\"db_title\" text," +
            "\"db_artist\" text," +
            "\"db_path\" text," +
            "\"db_duration\" integer," +
            "\"db_webId\" integer );"

    override fun onCreate(db: SQLiteDatabase) {
        db.execSQL(createTableMusic)
        myLog("MusicDataBase: createTable success")
    }

    override fun onUpgrade(db: SQLiteDatabase, oldVersion: Int, newVersion: Int) {
        db.execSQL("drop table if exists musicDB")
        myLog("MusicDataBase: onUpgrade")
        onCreate(db)
    }
/*    fun cvOf(vararg pairs: Pair<String, Any?>) = ContentValues().apply {
        for (pair in pairs) {
            val key = pair.first
            when (val value = pair.second) {
                is Int -> put(key, value)
                is Long -> put(key, value)
                is Short -> put(key, value)
                is Float -> put(key, value)
                is Double -> put(key, value)
                is Boolean -> put(key, value)
                is String -> put(key, value)
                is Byte -> put(key, value)
                is ByteArray -> put(key, value)
                null -> putNull(key)
            }
        }
    }*/
}
